package com.xinruke.hostels.dailymanage.controller;

import com.xinruke.hostels.common.controller.BaseController;
import com.xinruke.hostels.common.po.YwZhengjianxinxi;
import com.xinruke.hostels.common.po.constants.YwZhengjianxinxiConstants;
import com.xinruke.hostels.common.vo.ResultVO;
import com.xinruke.hostels.common.vo.query.RowsDataVO;
import com.xinruke.hostels.dailymanage.interfaces.dto.guest.*;
import com.xinruke.hostels.dailymanage.service.GuestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author yutaipu
 */
@RestController
@RequestMapping("/guest")
@Api(tags = "宾客管理")
@Slf4j
public class GuestController extends BaseController {

    @Autowired
    private GuestService guestService;

    @PostMapping(value = "/add")
    @ApiOperation("添加")
    public ResultVO add(@RequestBody @Valid GuestAddDTO params){
        return guestService.add(params);
    }

    @PostMapping(value = "/reservation/add")
    @ApiOperation("预订系统宾客添加")
    public ResultVO saveGuest(@RequestBody @Valid YwZhengjianxinxi ywZhengjianxinxi){
        ResultVO resultVO = ResultVO.fail();
        int i = guestService.saveGuest(ywZhengjianxinxi);
        if(i > 0){
            return ResultVO.success();
        }
        return  resultVO;
    }


    @PostMapping(value = "/modify")
    @ApiOperation("修改")
    public ResultVO modify(@RequestBody @Valid GuestModifyDTO params){
        return guestService.modify(params);
    }

    @PostMapping(value = "/delete")
    @ApiOperation("删除")
    public ResultVO delete(@RequestBody @Valid GuestDeleteDTO params){
        return guestService.delete(params);
    }

    @PostMapping(value = "/enable")
    @ApiOperation("启用")
    public ResultVO enable(@RequestBody @Valid GuestEnableDTO params){
        return guestService.updateStatus(params.getId(), YwZhengjianxinxiConstants.ZHUANGTAI_QIYONG);
    }

    @PostMapping(value = "/disable")
    @ApiOperation("禁用")
    public ResultVO disable(@RequestBody @Valid GuestDisableDTO params){
        return guestService.updateStatus(params.getId(), YwZhengjianxinxiConstants.ZHUANGTAI_JINYONG);
    }

    @PostMapping(value = "/addToBlacklist")
    @ApiOperation("批量加入黑名单")
    public ResultVO addToBlacklist(@RequestBody @Valid GuestAddToBlacklistDTO params){
        return guestService.updateStatus(params.getIdList(), YwZhengjianxinxiConstants.ZHUANGTAI_LAHEI);
    }

    @PostMapping(value = "/list")
    @ApiOperation(value = "查询宾客列表")
    public ResultVO<RowsDataVO<GuestQueryResultDTO>> list(@Valid @RequestBody GuestQueryListDTO params) {
        return guestService.list(params);
    }

    @PostMapping(value = "/detail")
    @ApiOperation(value = "查询宾客详情")
    public ResultVO<GuestQueryResultDTO> detail(@Valid @RequestBody GuestDetailDTO params){
        return guestService.detail(params);
    }

    @PostMapping("/list/like")
    @ApiOperation(("模糊查询宾客列表"))
    public ResultVO<RowsDataVO<GuestLikeQueryResultDTO>> likeQueryList(@Valid @RequestBody GuestLikeQueryDTO guestLikeQueryDTO){
        return guestService.likeQueryList(guestLikeQueryDTO);
    }
}
